<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.controller' );

/**
 * @package		Joomla
 * @subpackage	Config
 */
class FarmControllerOperation extends JController
{
	function __construct()
	{
		JRequest::setVar('view', 'operation');
		JRequest::setVar( 'layout', JRequest::getWord('task'));
		parent::__construct();
	}

	public function addPlantPlan()
	{
		JRequest::setVar('tmpl', 'component');
		parent::display();
	}
	
	public function savePlantPlan()
	{
		//保存种植信息基本信息
		$tField = JTable::getInstance('plantPlan', 'Table');
		if ($tField->newPlantPlan()) die('1');
		else die('0');
	}
	
	public function pplist()
	{
		parent::display();
	}
	
	public function addPlantRecord()
	{
		JRequest::setVar('tmpl', 'component');
		parent::display();
	}
	
	public function savePlantRecord()
	{
		$tField = JTable::getInstance('plantRecord', 'Table');
		if ($tField->newPlantRecord()) die('1');
		else die('0');
	}
	
	public function prlist()
	{
		parent::display();
	}
	
	public function addHarvestRecord()
	{
		JRequest::setVar('tmpl', 'component');
		parent::display();
	}
	
	public function saveHarvestRecord()
	{
		//保存种植信息基本信息
		$tField = JTable::getInstance('harvestRecord', 'Table');
		if ($tField->save($_POST)) die('1');
		else die($tField->getError());
	}
	
	public function hrlist()
	{
		parent::display();
	}
	
	public function addEnvironmentRecord()
	{
		JRequest::setVar('tmpl', 'component');
		parent::display();
	}
	
	public function saveEnvironmentRecord()
	{
		$tField = JTable::getInstance('environmentRecord', 'Table');
		if ($tField->save($_POST)) die('1');
		else die($tField->getError());
	}
	
	public function erlist()
	{
		parent::display();
	}
	
	public function getFieldAndPlantInfo()
	{
		$ppid = intval($_REQUEST['ppid']);
		
		if (!$ppid) die(json_encode(array()));
		
		$tPlantPlan = JTable::getInstance('plantPlan', 'Table');
		
		die(json_encode(array(
			'ppinfo'	=> $tPlantPlan->getInfo($ppid),
			'opeinfo'	=> $tPlantPlan->getOpes($ppid)
		)));
	}
}